(() => {
    let ele = {};
    ele.options = $('#tab-team li');

    ele.list_one = $('#list-one')//家族晋升

    ele.nowActive = $('#nowActive')//当前活跃度
    ele.sumActive = $('#sumActive')//累计活跃度
    ele.duihuan = $('#duihuan')//兑换

    // 领取成功
    ele.modal_successfully = $('#modal-successfully')
    ele.confirm_successfully = $('#confirm-successfully')
    // 领取成功
    ele.confirm_successfully.onclick = () => {
        ele.modal_successfully.style.display = 'none'
    }

    // 获取家族晋升列表
    getList();
    function getList() {
        let token = getCookie("token");
        let userid = getCookie("userid");
        ajax({
            url: API_PATH.PROMOTELIST,
            method: 'GET',
            header: {
                Authorization: token
            },
            success: res => {
                if (res.code == 1) drawPropList(res.data);
                else openTips(res.msg);
            }
        });
    }

    // 渲染家族晋升列表
    function drawPropList(data) {
        let html = '';
        for (let i = 0; i < data.length; i++) {
            let lv = data[i];
            let status = lv.complete ? 'saled' : 'sale';
            let txt = lv.complete == 1 ? '已达成' : '未达成';
            html += '<div class="giftbox">' +
                '<div class="giftimg">' +
                '<img src="http://img.qunx.top/xianwang/family/' + lv.id + '.png" alt="">' +
                '</div>' +
                '<div class="giftinfo">' +
                '<div class="gifttitle">' +
                '<span class="a1">' + lv.title + '</span>' +
                '</div>' +
                '<div class="gifttime">' +
                '<div class="giftc">' +
                '<p class="b1">直推一名仙王奖励' + lv.prize + '灵石</p>' +
                '<p class="b1">间推一名仙王奖励' + lv.prize_1 + '灵石</p>' +
                '</div>' +
                '<div class="' + status + '">' +
                '<span class="salen">' + txt + '</span>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>'

        }
        ele.list_one.innerHTML = html;
    }



    // 活跃度兑换零钱的数据
    getNum();
    function getNum() {
        let token = getCookie("token");
        let userid = getCookie("userid");
        ajax({
            url: API_PATH.SELFACTIVE,
            method: 'GET',
            header: {
                Authorization: token
            },
            success: res => {
                if (res.code == 1) {
                    ele.nowActive.innerHTML = res.data.current_family_active
                    ele.sumActive.innerHTML = res.data.family_active
                }
                else openTips(res.msg);
            }
        });
    }

    // 活跃度兑换零钱
    ele.duihuan.onclick = () => {
        let token = getCookie("token");
        let userid = getCookie("userid");
        ajax({
            url: API_PATH.ACTIVERECEIVE,
            method: 'POST',
            header: {
                Authorization: token
            },
            success: res => {
                if (res.code == 1) {
                    getNum()
                    ele.modal_successfully.style.display = 'block'
                }
                else openTips(res.msg);
            }
        });
    }


})();